home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / basic / RIBlitzLibs.lha / riblitzlibs / examples / riclock.asc < prev    next >
Encoding:
Text File  |  1994-10-23  |  9.8 KB  |  463 lines

  1. ;============== RIClock v2 ==========================
  2. ;= An example on how to use our commodities library =
  3. ;======= -------- Written by S Matty -------- =======
  4. ;     Publicscreen search routine by S McNamara
  5.  
  6.  
  7. WBStartup
  8. waitstatus.w=0
  9. popupstatus.w=0
  10. timeformat.w=0
  11. dtformat.w=0
  12. cscreen.b=-1
  13. DEFTYPE .l
  14. NEWTYPE .myscreen
  15.   pad.w
  16.   sname$
  17. End NEWTYPE
  18. Dim List screenlist.myscreen(50)
  19.  
  20. cscreen$="Workbench"
  21. pubopen=0
  22. n.l=0
  23. suc.l=0
  24. pubnum.w=0
  25. quitflag.l=0
  26. prefsopen.l=0
  27. twelvehour.l=0
  28. Statement GetPubScreenList {}
  29.   SHARED screenlist()
  30.  
  31.   ClearList screenlist()
  32.  
  33.   ad.l=LockPubScreenList_
  34.   UnlockPubScreenList_
  35.  
  36.   ad=Peek.l(ad)
  37.  
  38.   maxnum.w=50
  39.   Repeat
  40.     If Peek.l(ad+10)<>0
  41.       sname$=Peek$(Peek.l(ad+10))
  42.       If LockPubScreen_(sname$)
  43.         AddItem screenlist()
  44.         screenlist()\sname=sname$
  45.         UnlockPubScreen_ sname$,0
  46.       EndIf
  47.        ad=Peek.l(ad)
  48.        maxnum-1
  49.     Else
  50.       Statement Return
  51.     EndIf
  52.   Until maxnum=0
  53. End Statement
  54.  
  55.  
  56. MaxLen pubscreen$=100
  57. DateFormat 0
  58. NoCli
  59. WbToScreen 0
  60. Use Screen 0
  61. ShowScreen 0
  62. Dim tformat$(2)
  63. Dim dformat$(4)
  64. For n=1 To 2
  65.   Read tformat$(n)
  66. Next n
  67. For n=1 To 4
  68.   Read dformat$(n)
  69. Next n
  70. Data$ "HH:MM.SS","HH:MM"
  71. Data$" DD/MM/YY","MM/DD/YY","DD/MM","MM/DD"
  72. AddIDCMP $2000000
  73. screenhandle.l=Peek.l(Addr Screen(0))
  74. suc=GetIconObject("PROGDIR:RIClock")
  75.  
  76. suc=MakeCommodity("RIClock","RIClock v0.9","A Clock On Any PublicScreen")
  77. If suc=0 Then End
  78.  
  79. If suc
  80.   waitstatus=FindToolType("DONOTWAIT")
  81.   popup$=FindToolValue("CX_POPUP")
  82.   poppub$=FindToolValue("CX_POPPUB")
  83.   popkey$=FindToolValue("CX_POPKEY")
  84.   xpos$=FindToolValue("XPOS")
  85.   ypos$=FindToolValue("YPOS")
  86.   timeformat$=FindToolValue("TIMEFORMAT")
  87.   clockformat$=FindToolValue("CLOCKFORMAT")
  88.   dtformat$=FindToolValue("DATEFORMAT")
  89.   dt$=FindToolValue("DATE")
  90.   FreeIconObject
  91.   Gosub _usesettings
  92. Else
  93.   Gosub _default
  94. EndIf
  95.  
  96. Gosub drawtitle
  97. If popup$="YES"
  98.   Gosub drawprefs
  99. EndIf
  100. ResetTimer
  101. t.l=0
  102. .main
  103. Repeat
  104.   VWait
  105.   ev.l=Event
  106.   ew.w=EventWindow
  107.   gh.l=GadgetHit
  108.   ec.l=EventCode
  109.   Select ew
  110.     Case 0
  111.       Gosub titleclock
  112.     Case 1
  113.       Gosub prefs
  114.     Case 2
  115.       Gosub pubscreen
  116.   End Select
  117.   ev=0
  118.   ew=0
  119.   If paused=0
  120.     If Timer-t>=50
  121.       t=0
  122.       ResetTimer
  123.       Gosub updatetitle
  124.     EndIf
  125.   EndIf
  126.   If CommodityEvent
  127.     Select ExchangeMessage
  128.       Case CxKill
  129.         End
  130.       Case CxDisable
  131.         Gosub pause
  132.       Case CxEnable
  133.         Gosub unpause
  134.       Case CxAppear
  135.         Gosub drawprefs
  136.       Case CxDisAppear
  137.         Gosub closeprefs
  138.       Case CxUnique
  139.         Gosub drawprefs
  140.     End Select
  141.     Select HotKeyHit
  142.       Case 0
  143.         Gosub drawprefs
  144.       Case 1
  145.         Gosub drawpub
  146.     End Select
  147.   EndIf
  148. Until quitflag
  149. End
  150.  
  151. ; Find out all currently available public screens
  152. .getpubscreens:
  153. If pubopen=True
  154.   GTChangeList 1,63
  155. EndIf
  156.   GetPubScreenList{}
  157. If pubopen=True
  158.    GTChangeList 1,63,screenlist()
  159.    GTSetAttrs 1,63,GTTagValue(54),0
  160. EndIf
  161. Return
  162.  
  163. ;Disable our commodity
  164. .pause:
  165.   If paused=0 Then CloseWindow 0:SetStatus Off
  166.   paused=-1
  167. Return
  168.  
  169. ;Enable our Commodity
  170. .unpause:
  171.   If paused=-1 Then Gosub drawtitle:SetStatus On
  172.   paused=0
  173. Return
  174.  
  175. ;The routine to handle all PublibScreen events
  176. .pubscreen:
  177.   If ev=0 Then Return
  178.   Select ev
  179.     Case $200       ; Close gadget
  180.       If pubopen
  181.         pubopen=0
  182.         CloseWindow 2
  183.       EndIf
  184.     Case $40        ; We hit something
  185.       Select gh
  186.       Case 63       ; The list view?
  187.         ResetList screenlist()
  188.         For n=0 To ec
  189.           NextItem screenlist()
  190.         Next n
  191.         If screenlist()\sname<>cscreen$
  192.           cscreen$=screenlist()\sname
  193.           scrlock.l=LockPubScreen_(screenlist()\sname)
  194.           If scrlock=0 Then errflag=True
  195.           If scrlock
  196.             CloseWindow 0
  197.             If prefsopen=True Then Gosub closeprefs
  198.             If pubopen=True Then Gosub closepub
  199.             Poke.l Addr Screen(0),scrlock
  200.             Use Screen 0
  201.             Gosub drawtitle
  202.             UnlockPubScreen_ 0,scrlock
  203.             ShowScreen 0
  204.           EndIf
  205.         EndIf
  206.       Case 67       ; The Update button
  207.           Gosub getpubscreens
  208.     End Select
  209.   End Select
  210. Return
  211.  
  212. ;Draw the public screen window
  213. .drawpub:
  214.   Use Screen 0
  215.   If pubopen Then Return
  216.   Gosub getpubscreens
  217.   Use Screen 0
  218.   GTListView 1,63,16,14,180,80,"Screens",0,screenlist(),0
  219.   GTButton 1,67,16,91,180,12,"Update List",0
  220.   Window 2,(ScreenWidth/2)-130,(ScreenHeight/2)-60,260,120,$100a,"Public Screen",2,1,0
  221.   AttachGTList 1,2
  222.   pubopen=True
  223. Return
  224.  
  225. .closepub:        ; Close the PublicScreen window
  226.   pubopen=0
  227.   CloseWindow 2
  228. Return
  229.  
  230. ;Open the clock window
  231. .drawtitle:
  232. Window 0,xpos,ypos,160,11,$f,"",2,1
  233. Gosub updatetitle
  234. Return
  235.  
  236. .titleclock:      ; The main clock window
  237. If ev=0 Then Return
  238. Select ev
  239.   Case $200       ; The Close gadget
  240.     quitflag=True
  241.   Case $2000000   ; We have moved the window
  242.     uw.l=Used Window
  243.     Use Window 0
  244.     xpos.w=WindowX
  245.     ypos.w=WindowY
  246.     Use Window uw
  247.     If prefsopen=-1
  248.         GTSetInteger 0,50,xpos
  249.         GTSetInteger 0,51,ypos
  250.     EndIf
  251. End Select
  252. FlushEvents
  253. ev=0
  254. Return
  255.  
  256. .prefs:
  257.   If ev=0 Then Return
  258.   Select ev
  259.     Case $400
  260.         Select ec
  261.             Case 50
  262.                ActivateString 1,50
  263.             Case 21
  264.                ActivateString 1,51
  265.             Case 25
  266.                ActivateString 1,60
  267.             Case 51
  268.                ActivateString 1,61
  269.             Case 33
  270.                Gosub saveprefs
  271.             Case 22
  272.                ActivateString 1,64
  273.             Case 16
  274.                End
  275.         End Select
  276.     Case $200
  277.         Gosub closeprefs
  278.     Case $40
  279.         Select gh
  280.             Case 50
  281.               xpos.w=GTGetInteger(0,50)
  282.               ypos.w=GTGetInteger(0,51)
  283.               If paused=0
  284.                 Use Window 0
  285.                 WMove xpos,ypos
  286.               EndIf
  287.             Case 54
  288.               twelvehour=NOT(twelvehour)
  289.             Case 58
  290.               dtenabled=NOT(dtenabled)
  291.             Case 59
  292.               Gosub saveprefs
  293.             Case 60
  294.               popkey$=GTGetString(0,60)
  295.               suc=SetHotKey(0,popkey$)
  296.             Case 62
  297.               popup$="YES"
  298.               popupstatus=NOT(popupstatus)
  299.               If popupstatus=0 Then popup$="NO"
  300.             Case 63
  301.               waitstatus=NOT(waitstatus)
  302.             Case 64
  303.               poppub$=GTGetString(0,64)
  304.               suc=SetHotKey(1,poppub$)
  305.             Case 65
  306.               End
  307.             Case 66
  308.               Gosub _default
  309.               Gosub closeprefs
  310.               Gosub drawprefs
  311.           End Select
  312.     Case $20          ; The Mutually Exclusive gadget?
  313.         Select gh
  314.           Case 52
  315.             timeformat=ec
  316.           Case 57
  317.             dtformat=ec
  318.         End Select
  319.   End Select
  320.  
  321. Return
  322.  
  323. .drawprefs:
  324. If prefsopen.l Then Return
  325. prefsopen.l=-1
  326. If paused=0
  327.   GTInteger 0,50,20,4,48,12,"_X",0,xpos
  328.   GTInteger 0,51,112,4,48,12,"_Y",0,ypos
  329.  
  330.   GTMX 0,52,4,32,14,8,"?",2|$200,"HH:MM.SS|HH:MM",timeformat
  331.   GTMX 0,57,160,32,14,8,"?",2|$200,"DD/MM/YY|MM/DD/YY|DD/MM|MM/DD",dtformat
  332.  
  333.   GTText 0,55,0,24,1,1,"",0,"Time Format"
  334.   GTText 0,56,156,24,1,1,"",0,"Date Format"
  335.  
  336.   GTCheckBox 0,54,4,70,16,16,"24 Hour",2
  337.   GTCheckBox 0,58,160,70,16,16,"Enabled",2
  338.   GTCheckBox 0,62,4,136,16,16,"PopUp?",2
  339.   GTCheckBox 0,63,4,150,16,16,"DoNotWait",2
  340.  
  341.   GTButton 0,59,4,172,72,12," Save ",0
  342.   GTButton 0,65,116,172,72,12," Quit ",0
  343.   GTButton 0,66,226,172,80,12," Default ",0
  344.  
  345.   GTString 0,60,76,82,216,12,"  _PopKey",0,50,popkey$
  346.   GTString 0,64,76,100,216,12,"  P_ubKey",0,50,poppub$
  347.  
  348.   GTToggle 0,54,NOT(twelvehour)
  349.   GTToggle 0,58,dtenabled
  350.   GTToggle 0,62,popupstatus
  351.   GTToggle 0,63,waitstatus
  352.  
  353. EndIf
  354. Window 1,(ScreenWidth/2)-160,(ScreenHeight/2)-100,320,200,$1000a,"Clock Prefs",2,1,0
  355. AttachGTList 0,1
  356. Activate 1
  357. Return
  358.  
  359. ;Close the preferences window
  360. .closeprefs:
  361.   If prefsopen=0 Then Return
  362.   prefsopen.l=0
  363.   CloseWindow 1
  364.   Free GTList 0
  365. Return
  366.  
  367. ;Save our preferences
  368. .saveprefs:
  369.   suc=GetIconObject("PROGDIR:RIClock")
  370.   ClearToolTypes
  371.   If waitstatus=-1 Then NewToolType "DONOTWAIT",""
  372.   NewToolType "CX_POPUP",popup$
  373.   NewToolType "CX_POPPUB",poppub$
  374.   NewToolType "CX_POPKEY",popkey$
  375.   NewToolType "XPOS",Str$(xpos)
  376.   NewToolType "YPOS",Str$(ypos)
  377.   NewToolType "TIMEFORMAT",tformat$(timeformat+1)
  378.   NewToolType "DATEFORMAT",dformat$(dtformat+1)
  379.   NewToolType "CLOCKFORMAT",Str$(12*(twelvehour+2))
  380.   dte$="NO"
  381.   If dtenabled=-1 Then dte$="YES"
  382.   NewToolType "DATE",dte$
  383.   suc=PutIconObject("PROGDIR:RIClock")
  384.   If suc=0 Then Request "RIClock","Error saving tooltypes"," OK ":End
  385.   FreeIconObject
  386.   Gosub closeprefs
  387. Return
  388.  
  389. .updatetitle:
  390. hr$=Str$(Hours)
  391. If Len(hr$)=0 AND twelvehour Then hr$="0"+hr$
  392. mn$=Str$(Mins)
  393. If Len(mn$)=1 Then mn$="0"+mn$
  394. sc$=Str$(Secs)
  395. If Len(sc$)=1 Then sc$="0"+sc$
  396. dt$=Date$(SystemDate)
  397. day$=Str$(Days)
  398. month$=Str$(Months)
  399. year$=Str$(Years)
  400. If twelvehour AND Val(hr$)>12 Then hr$=Str$(Val(hr$)-12)
  401. Select timeformat
  402.   Case 0
  403.     title$=hr$+":"+mn$+"."+sc$
  404.   Case 1
  405.     tccounter=1-tccounter
  406.     If tccounter=0
  407.       title$=hr$+":"+mn$
  408.     Else
  409.       title$=hr$+" "+mn$
  410.     EndIf
  411. End Select
  412. If dtenabled
  413.   tccounter=1
  414.   dtcounter=1-dtcounter
  415.   If dtcounter=0
  416.      Select dtformat
  417.         Case 0
  418.            title$=day$+"/"+month$+"/"+year$
  419.         Case 1
  420.            title$=month$+"/"+day$+"/"+year$
  421.         Case 2
  422.            title$=day$+"/"+month$
  423.         Case 3
  424.            title$=month$+"/"+day$
  425.      End Select
  426.   EndIf
  427. EndIf
  428. ;Dont adjust the clock title!
  429. SetWindowTitles_ Peek.l(Addr Window(0)),title$,-1
  430. Return
  431.  
  432. ._default:
  433. waitstatus.w=-1
  434. popup$="NO"
  435. popkey$="ctrl lshift c"
  436. poppub$="ctrl lshift p"
  437. xpos$=Str$(ScreenWidth-160)
  438. ypos$="11"
  439. timeformat$="HH:MM.SS"
  440. dtformat$="DD/MM/YY"
  441. dt$="NO"
  442. Gosub _usesettings
  443. Return
  444.  
  445. ._usesettings:
  446. twelvehour=(clockformat$="12")
  447. dtenabled.l=(dt$="YES")
  448. popupstatus.w=(popup$="YES")
  449. xpos.w=Val(xpos$)
  450. ypos.w=Val(ypos$)
  451. timeformat.w=0
  452. For n=1 To 2
  453.   If tformat$(n)=timeformat$ Then timeformat.w=n-1
  454. Next n
  455.  
  456. dformat.w=0
  457. For n=1 To 2
  458.   If dformat$(n)=dtformat$ Then dtformat.w=n-1
  459. Next n
  460. suc=SetHotKey(0,popkey$)
  461. suc=SetHotKey(1,poppub$)
  462. Return
  463.